package com.huawei.classroom.student.h52;

import java.util.Set;
import java.util.HashSet;
public class NumDecompose {
	/**
	 * 将num进行质因数分解，将分解到的质因数放到Set里面返回
	 */
	public Set<Integer> decompose(int num) {
		Set<Integer> set = new HashSet<>();
		for(int i=2; i<=num; i++) {
			if(num % i == 0) {
				if(set.contains(i)) {
					continue;
				}
				if(judge(i))
					set.add(i);
			}
		}
		System.out.println(set);
		return set;
		
	}
	
	public boolean judge(int i) {
		if(i == 2) return true;
		for(int j=2; j<Math.sqrt(i)+1; j++) {
			if(i % j == 0)
				return false;
		}
		return true;
	}
}
